<div id="pages_mall_region_list" class="scroll" style="height:100%;display:none;"><master :show-top="platform == 'Web' || platform == 'iOS' || platform == 'Android'" :title="title">
  <listpage ref="listpage"></listpage>
</master></div>
<script type="text/javascript">
(function (G) {
  G.vue("pages_mall_region_list",{
  "usingComponents": {
    "master": "/components/Master/Master",
    "listpage": "/components/List/Page/Page"
  },
  "enablePullDownRefresh": true
},{
    data: {
      title: '',
      type:'',
      modelName: '',
      models: {},
      nickName: '',
      platform: G.platform
    },
    methods: {
      load: function (next) {
        this.selectComponent('#listpage').load(next);
      },
      refresh: function (next) {
        this.selectComponent('#listpage').refresh(next);
      },
      onPullDownRefresh: function (event) {
        this.refresh(function () {
          $.stopPullDownRefresh();
        })
      },
      onReachBottom: function (event) {
        this.load();
      },
      edit: function (event) {
        var type = this.getData('type');
        var modeleditquery = {
          values: { type: type},
          refresh: this.refresh,
          models: this.getData('models'),
          url: '/api/model/' + this.getData('modelName')
        }
        var imgSize = {
          banner:{width:676,height:344},
          category:{width:100,height:100},
          recommend:{width:676,height:290}
        }
        if(imgSize[type]) modeleditquery.models.img.attr = imgSize[type];
        if (event.type == 'edit') {
          modeleditquery.values = event.detail;
          modeleditquery.title = '修改 ' + this.getData('nickName');
          modeleditquery.meth = 'PUT';
        } else {
          modeleditquery.title = '新增 ' + this.getData('nickName');
          modeleditquery.meth = 'POST';
        }
        G.Storage.set('modeleditquery', modeleditquery);
        this.$go('/pages/model/edit/edit');
      }
    },
    mounted: function (query) {
      var _this = this;
      query.modelName = 'index_region';
      var nickName = query.name;
      G.ajax('/model/' + query.modelName, function (ret) {
        if (!ret.errorMsg) {
          var edit = {};
          for (var key in ret) if (ret[key].label && /switch/.test(ret[key].type)) edit[key] = '/api/model/' + query.modelName;
          _this.selectComponent('#listpage').init({
            getUrl: {
              url: '/api/model/' + query.modelName,
              data: { type: query.type }
            },
            models: ret,
            edit: edit,
            canBack:true,
            actions: {
              edit: {
                action: function (event) {
                  _this.edit(event);
                },
                name: '修改'
              },
              delet: {
                action: '/api/model/' + query.modelName,
                name: '删除'
              },
              add: {
                action: function (event) {
                  _this.edit(event);
                },
                name: '新增'
              }
            }
          })
          _this.load();
          _this.setData({ type:query.type ,models: ret, nickName: nickName, title: nickName + '列表', modelName: query.modelName });
        }
      }, {
          itemName: query.modelName + 'Model'
        })
    }
  });
})(Y)
</script>